<?php

namespace App\Http\Controllers\Admin\System;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Link;
use App\Flight;
use Illuminate\Support\Facades\Redis;

class friendLinkController extends Controller
{
    public function list()
    {

    	$list = link::select('id', 'name', 'http_address', 'content')->where('state', 0)->get();

    	return view('Admin/System/friendlink', ['list'=>$list]);
    }

    public function add(Request $request)
    {
    	$mod = new Link;

    	$mod->name = $request->all()['name'];

    	$mod->http_address = $request->all()['url'];

    	$mod->content = $request->all()['content'];

    	$mod->state = 0;

    	$mod->save();

    	$list = link::select('id', 'name', 'http_address', 'content')->where('state', 0)->get();

    	Redis::del('friendLink');
        
        return redirect()->action('Admin\System\friendLinkController@list'); 
    }

    public function del()
    {
        $res = link::find($_GET['id']);
        $res->state = 1;
        $aa = $res->save();
        Redis::del('friendLink');
        return 1;
    }

    public function edit()
    {
        $keys = [];
        $values = [];
        if(!$_GET['id']){
            exit;
        }
        foreach ($_GET as $key => $value) {
            $keys = $key;
            $values = $value;
        }
        $res = link::find($_GET['id']);
        $res->$keys = $values;
        $aa = $res->save();
        Redis::del('friendLink');
        return 1;

    }
}
